package cn.jluzh.blog.modules.security.eneity;

import cn.jluzh.blog.modules.user.entity.SysUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
/**
 * 用户
 *
 * @author pixiaoyong
 */
public class SecurityUser {

    public static Subject getSubject() {
        try {
            return SecurityUtils.getSubject();
        }catch (Exception e){
            return null;
        }
    }

    /**
     * 获取用户信息
     */
    public static SysUser getUser() {
        Subject subject = getSubject();
        if(subject == null){
            return new SysUser();
        }

        SysUser user = (SysUser)subject.getPrincipal();
        if(user == null){
            return new SysUser();
        }

        return user;
    }

    /**
     * 获取用户ID
     */
    public static Integer getUserId() {
        return getUser().getId();
    }

    /**
     * 获取部门ID
     * public static Long getDeptId() {
     *         return getUser().getDeptId();
     *     }
     */
}